package cn.cupk.corporateshuttlemanagesystem.mapper;

import cn.cupk.corporateshuttlemanagesystem.pojo.Routes;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RouteInformationMapper {

    @Select({
            "<script>",
            "SELECT routes.*, buses.license_plate as licensePlate FROM routes",
            "LEFT JOIN buses ON routes.bus_id = buses.bus_id",
            "<where>",
            "<if test='username != null'>",
            "AND routes.name LIKE CONCAT('%', #{username}, '%')",
            "</if>",
            "</where>",
            "</script>"
    })
    List<Routes> page(Routes routes);


    @Select("SELECT * FROM routes WHERE name = #{name}")
    Routes selectOne(String name);

    @Insert("INSERT INTO routes(name,bus_id,company_id,start_time,end_time,stops_id) VALUES(#{name},#{busId},#{companyId},#{startTime},#{endTime},#{stopsId})")
    Integer add(Routes routes);

    @Update("UPDATE routes set name = #{name},company_id = #{companyId},start_time = #{startTime},end_time = #{endTime} WHERE route_id=#{routeId}")
    Integer update(Routes routes);
}
